{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# QUANTAXIS 从web获取数据教程"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "本notebook旨在提供一个可视可交互的ipyb文件以展示QA如何从web获取各种数据，如果你想试试这些代码的效果，请下载本notebook文件到本地使用。\n",
    "\n",
    "核心函数是QA_fetch_get_xxxxxx(数据来源,代码,日期/时间参数...）\n",
    "\n",
    "我们没有完整的演示所有数据获取接口，需要的话请查看文档或源代码。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 这一步请自行安装QA，如果报错请先自行安装报错提示缺少的包再试试，最后不行再去论坛或Q群提问，谢谢！\n",
    "import QUANTAXIS as QA"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 股票数据\n",
    "\n",
    "1. 获取股票列表\n",
    "2. 获取股票日线\n",
    "3. 获取股票分钟线\n",
    "4. 获取股票分笔数据"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 1. 股票列表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>code</th>\n",
       "      <th>volunit</th>\n",
       "      <th>decimal_point</th>\n",
       "      <th>name</th>\n",
       "      <th>pre_close</th>\n",
       "      <th>sse</th>\n",
       "      <th>sec</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>code</th>\n",
       "      <th>sse</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>000001</th>\n",
       "      <th>sz</th>\n",
       "      <td>000001</td>\n",
       "      <td>100</td>\n",
       "      <td>2</td>\n",
       "      <td>平安银行</td>\n",
       "      <td>16.450001</td>\n",
       "      <td>sz</td>\n",
       "      <td>stock_cn</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>000002</th>\n",
       "      <th>sz</th>\n",
       "      <td>000002</td>\n",
       "      <td>100</td>\n",
       "      <td>2</td>\n",
       "      <td>万 科Ａ</td>\n",
       "      <td>26.420000</td>\n",
       "      <td>sz</td>\n",
       "      <td>stock_cn</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>000004</th>\n",
       "      <th>sz</th>\n",
       "      <td>000004</td>\n",
       "      <td>100</td>\n",
       "      <td>2</td>\n",
       "      <td>国农科技</td>\n",
       "      <td>18.350000</td>\n",
       "      <td>sz</td>\n",
       "      <td>stock_cn</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "              code  volunit  decimal_point  name  pre_close sse       sec\n",
       "code   sse                                                               \n",
       "000001 sz   000001      100              2  平安银行  16.450001  sz  stock_cn\n",
       "000002 sz   000002      100              2  万 科Ａ  26.420000  sz  stock_cn\n",
       "000004 sz   000004      100              2  国农科技  18.350000  sz  stock_cn"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "QA.QA_fetch_get_stock_list('tdx').head(3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2.股票日线\n",
    "\n",
    "\n",
    "QA.QA_fetch_get_stock_day(\n",
    "    package,\n",
    "    code,\n",
    "    start,\n",
    "    end,\n",
    "    if_fq='01',\n",
    "    level='day',\n",
    "    type_='pd',\n",
    ")\n",
    "\n",
    "if_fq的意思是是否复权，可以选择qfq:前复权 或者 bfq:不复权 或者 hfq:后复权"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>close</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>vol</th>\n",
       "      <th>amount</th>\n",
       "      <th>date</th>\n",
       "      <th>code</th>\n",
       "      <th>date_stamp</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2018-08-01</th>\n",
       "      <td>9.42</td>\n",
       "      <td>9.15</td>\n",
       "      <td>9.50</td>\n",
       "      <td>9.11</td>\n",
       "      <td>814081.0</td>\n",
       "      <td>759282240.0</td>\n",
       "      <td>2018-08-01</td>\n",
       "      <td>000001</td>\n",
       "      <td>1.533053e+09</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-08-02</th>\n",
       "      <td>9.13</td>\n",
       "      <td>8.94</td>\n",
       "      <td>9.15</td>\n",
       "      <td>8.88</td>\n",
       "      <td>931401.0</td>\n",
       "      <td>839272256.0</td>\n",
       "      <td>2018-08-02</td>\n",
       "      <td>000001</td>\n",
       "      <td>1.533139e+09</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2018-08-03</th>\n",
       "      <td>8.93</td>\n",
       "      <td>8.91</td>\n",
       "      <td>9.10</td>\n",
       "      <td>8.91</td>\n",
       "      <td>476546.0</td>\n",
       "      <td>428641536.0</td>\n",
       "      <td>2018-08-03</td>\n",
       "      <td>000001</td>\n",
       "      <td>1.533226e+09</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            open  close  high   low       vol       amount        date  \\\n",
       "date                                                                     \n",
       "2018-08-01  9.42   9.15  9.50  9.11  814081.0  759282240.0  2018-08-01   \n",
       "2018-08-02  9.13   8.94  9.15  8.88  931401.0  839272256.0  2018-08-02   \n",
       "2018-08-03  8.93   8.91  9.10  8.91  476546.0  428641536.0  2018-08-03   \n",
       "\n",
       "              code    date_stamp  \n",
       "date                              \n",
       "2018-08-01  000001  1.533053e+09  \n",
       "2018-08-02  000001  1.533139e+09  \n",
       "2018-08-03  000001  1.533226e+09  "
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "QA.QA_fetch_get_stock_day('tdx','000001','2018-08-01','2018-08-10',if_fq='bfq').head(3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 3.股票分钟线\n",
    "\n",
    "QA.QA_fetch_get_stock_min(package, code, start, end, level='1min')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>close</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>vol</th>\n",
       "      <th>amount</th>\n",
       "      <th>datetime</th>\n",
       "      <th>code</th>\n",
       "      <th>date</th>\n",
       "      <th>date_stamp</th>\n",
       "      <th>time_stamp</th>\n",
       "      <th>type</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>datetime</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-08-30 09:31:00</th>\n",
       "      <td>14.29</td>\n",
       "      <td>14.32</td>\n",
       "      <td>14.33</td>\n",
       "      <td>14.29</td>\n",
       "      <td>4387700.0</td>\n",
       "      <td>62754528.0</td>\n",
       "      <td>2019-08-30 09:31:00</td>\n",
       "      <td>000001</td>\n",
       "      <td>2019-08-30</td>\n",
       "      <td>1.567094e+09</td>\n",
       "      <td>1.567129e+09</td>\n",
       "      <td>1min</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-30 09:32:00</th>\n",
       "      <td>14.32</td>\n",
       "      <td>14.38</td>\n",
       "      <td>14.38</td>\n",
       "      <td>14.32</td>\n",
       "      <td>2781400.0</td>\n",
       "      <td>39923096.0</td>\n",
       "      <td>2019-08-30 09:32:00</td>\n",
       "      <td>000001</td>\n",
       "      <td>2019-08-30</td>\n",
       "      <td>1.567094e+09</td>\n",
       "      <td>1.567129e+09</td>\n",
       "      <td>1min</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-30 09:33:00</th>\n",
       "      <td>14.37</td>\n",
       "      <td>14.35</td>\n",
       "      <td>14.37</td>\n",
       "      <td>14.33</td>\n",
       "      <td>1464400.0</td>\n",
       "      <td>21015736.0</td>\n",
       "      <td>2019-08-30 09:33:00</td>\n",
       "      <td>000001</td>\n",
       "      <td>2019-08-30</td>\n",
       "      <td>1.567094e+09</td>\n",
       "      <td>1.567129e+09</td>\n",
       "      <td>1min</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                      open  close   high    low        vol      amount  \\\n",
       "datetime                                                                 \n",
       "2019-08-30 09:31:00  14.29  14.32  14.33  14.29  4387700.0  62754528.0   \n",
       "2019-08-30 09:32:00  14.32  14.38  14.38  14.32  2781400.0  39923096.0   \n",
       "2019-08-30 09:33:00  14.37  14.35  14.37  14.33  1464400.0  21015736.0   \n",
       "\n",
       "                                datetime    code        date    date_stamp  \\\n",
       "datetime                                                                     \n",
       "2019-08-30 09:31:00  2019-08-30 09:31:00  000001  2019-08-30  1.567094e+09   \n",
       "2019-08-30 09:32:00  2019-08-30 09:32:00  000001  2019-08-30  1.567094e+09   \n",
       "2019-08-30 09:33:00  2019-08-30 09:33:00  000001  2019-08-30  1.567094e+09   \n",
       "\n",
       "                       time_stamp  type  \n",
       "datetime                                 \n",
       "2019-08-30 09:31:00  1.567129e+09  1min  \n",
       "2019-08-30 09:32:00  1.567129e+09  1min  \n",
       "2019-08-30 09:33:00  1.567129e+09  1min  "
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "QA.QA_fetch_get_stock_min('tdx','000001','2019-08-30 09:30:00','2019-08-31 15:00:00').head(3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 4. 股票分笔数据\n",
    "\n",
    "QA.QA_fetch_get_stock_transaction(package, code, start, end, retry=2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "QUANTAXIS>> Successfully Getting 000001 history transaction data in day 2019-08-30\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>time</th>\n",
       "      <th>price</th>\n",
       "      <th>vol</th>\n",
       "      <th>buyorsell</th>\n",
       "      <th>date</th>\n",
       "      <th>datetime</th>\n",
       "      <th>code</th>\n",
       "      <th>order</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>datetime</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-08-30 09:25:00</th>\n",
       "      <td>09:25</td>\n",
       "      <td>14.29</td>\n",
       "      <td>14071</td>\n",
       "      <td>2</td>\n",
       "      <td>2019-08-30</td>\n",
       "      <td>2019-08-30 09:25:00</td>\n",
       "      <td>000001</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-30 09:30:00</th>\n",
       "      <td>09:30</td>\n",
       "      <td>14.29</td>\n",
       "      <td>9434</td>\n",
       "      <td>0</td>\n",
       "      <td>2019-08-30</td>\n",
       "      <td>2019-08-30 09:30:00</td>\n",
       "      <td>000001</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-08-30 09:30:00</th>\n",
       "      <td>09:30</td>\n",
       "      <td>14.31</td>\n",
       "      <td>3043</td>\n",
       "      <td>0</td>\n",
       "      <td>2019-08-30</td>\n",
       "      <td>2019-08-30 09:30:00</td>\n",
       "      <td>000001</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                      time  price    vol  buyorsell        date  \\\n",
       "datetime                                                          \n",
       "2019-08-30 09:25:00  09:25  14.29  14071          2  2019-08-30   \n",
       "2019-08-30 09:30:00  09:30  14.29   9434          0  2019-08-30   \n",
       "2019-08-30 09:30:00  09:30  14.31   3043          0  2019-08-30   \n",
       "\n",
       "                                datetime    code  order  \n",
       "datetime                                                 \n",
       "2019-08-30 09:25:00  2019-08-30 09:25:00  000001      0  \n",
       "2019-08-30 09:30:00  2019-08-30 09:30:00  000001      1  \n",
       "2019-08-30 09:30:00  2019-08-30 09:30:00  000001      2  "
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "QA.QA_fetch_get_stock_transaction('tdx','000001','2019-08-30','2019-08-30').head(3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 期货数据\n",
    "1. 获取期货列表\n",
    "2. 获取期货日线\n",
    "3. 获取期货分钟线\n",
    "4. 获取期货分笔数据"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 1. 期货列表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>category</th>\n",
       "      <th>market</th>\n",
       "      <th>code</th>\n",
       "      <th>name</th>\n",
       "      <th>desc</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>code</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>AU2012</th>\n",
       "      <td>3</td>\n",
       "      <td>30</td>\n",
       "      <td>AU2012</td>\n",
       "      <td>黄金2012</td>\n",
       "      <td>AU2012</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>AUL8</th>\n",
       "      <td>3</td>\n",
       "      <td>30</td>\n",
       "      <td>AUL8</td>\n",
       "      <td>黄金主连</td>\n",
       "      <td>AUL8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>AUL9</th>\n",
       "      <td>3</td>\n",
       "      <td>30</td>\n",
       "      <td>AUL9</td>\n",
       "      <td>黄金指数</td>\n",
       "      <td>AUL9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>BU1912</th>\n",
       "      <td>3</td>\n",
       "      <td>30</td>\n",
       "      <td>BU1912</td>\n",
       "      <td>沥青1912</td>\n",
       "      <td>BU1912</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>BU2001</th>\n",
       "      <td>3</td>\n",
       "      <td>30</td>\n",
       "      <td>BU2001</td>\n",
       "      <td>沥青2001</td>\n",
       "      <td>BU2001</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        category  market    code    name    desc\n",
       "code                                            \n",
       "AU2012         3      30  AU2012  黄金2012  AU2012\n",
       "AUL8           3      30    AUL8    黄金主连    AUL8\n",
       "AUL9           3      30    AUL9    黄金指数    AUL9\n",
       "BU1912         3      30  BU1912  沥青1912  BU1912\n",
       "BU2001         3      30  BU2001  沥青2001  BU2001"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "QA.QA_fetch_get_future_list('tdx').head(5)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2.期货日线\n",
    "\n",
    "\n",
    "QA.QA_fetch_get_future_day(package, code, start, end, frequence='day')\n",
    "\n",
    "**注意合约名要大写！**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "      <th>position</th>\n",
       "      <th>trade</th>\n",
       "      <th>price</th>\n",
       "      <th>amount</th>\n",
       "      <th>date</th>\n",
       "      <th>code</th>\n",
       "      <th>date_stamp</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-11-01</th>\n",
       "      <td>620.0</td>\n",
       "      <td>630.0</td>\n",
       "      <td>614.0</td>\n",
       "      <td>625.5</td>\n",
       "      <td>1571710</td>\n",
       "      <td>17666</td>\n",
       "      <td>622.5</td>\n",
       "      <td>2.202435e-39</td>\n",
       "      <td>2019-11-01</td>\n",
       "      <td>I2001</td>\n",
       "      <td>1.572538e+09</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-11-04</th>\n",
       "      <td>625.0</td>\n",
       "      <td>626.0</td>\n",
       "      <td>612.5</td>\n",
       "      <td>615.0</td>\n",
       "      <td>1533962</td>\n",
       "      <td>15625</td>\n",
       "      <td>618.5</td>\n",
       "      <td>2.149539e-39</td>\n",
       "      <td>2019-11-04</td>\n",
       "      <td>I2001</td>\n",
       "      <td>1.572797e+09</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-11-05</th>\n",
       "      <td>614.0</td>\n",
       "      <td>624.5</td>\n",
       "      <td>610.5</td>\n",
       "      <td>622.0</td>\n",
       "      <td>1573306</td>\n",
       "      <td>16716</td>\n",
       "      <td>617.0</td>\n",
       "      <td>2.204671e-39</td>\n",
       "      <td>2019-11-05</td>\n",
       "      <td>I2001</td>\n",
       "      <td>1.572883e+09</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             open   high    low  close  position  trade  price        amount  \\\n",
       "date                                                                           \n",
       "2019-11-01  620.0  630.0  614.0  625.5   1571710  17666  622.5  2.202435e-39   \n",
       "2019-11-04  625.0  626.0  612.5  615.0   1533962  15625  618.5  2.149539e-39   \n",
       "2019-11-05  614.0  624.5  610.5  622.0   1573306  16716  617.0  2.204671e-39   \n",
       "\n",
       "                  date   code    date_stamp  \n",
       "date                                         \n",
       "2019-11-01  2019-11-01  I2001  1.572538e+09  \n",
       "2019-11-04  2019-11-04  I2001  1.572797e+09  \n",
       "2019-11-05  2019-11-05  I2001  1.572883e+09  "
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "QA.QA_fetch_get_future_day('tdx','I2001','2019-11-01','2019-11-10').head(3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 3.期货分钟线\n",
    "\n",
    "QA.QA_fetch_get_future_min(package, code, start, end, frequence='1min')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "      <th>position</th>\n",
       "      <th>trade</th>\n",
       "      <th>price</th>\n",
       "      <th>datetime</th>\n",
       "      <th>amount</th>\n",
       "      <th>tradetime</th>\n",
       "      <th>code</th>\n",
       "      <th>date</th>\n",
       "      <th>date_stamp</th>\n",
       "      <th>time_stamp</th>\n",
       "      <th>type</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>datetime</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-11-01 09:30:00</th>\n",
       "      <td>618.0</td>\n",
       "      <td>618.0</td>\n",
       "      <td>617.0</td>\n",
       "      <td>617.5</td>\n",
       "      <td>1510450</td>\n",
       "      <td>2814</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2019-11-01 09:30:00</td>\n",
       "      <td>2.116591e-39</td>\n",
       "      <td>2019-11-01 09:30</td>\n",
       "      <td>I2001</td>\n",
       "      <td>2019-11-01</td>\n",
       "      <td>1.572538e+09</td>\n",
       "      <td>1.572572e+09</td>\n",
       "      <td>1min</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-11-01 09:31:00</th>\n",
       "      <td>617.5</td>\n",
       "      <td>617.5</td>\n",
       "      <td>617.0</td>\n",
       "      <td>617.5</td>\n",
       "      <td>1510914</td>\n",
       "      <td>3998</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2019-11-01 09:31:00</td>\n",
       "      <td>2.117241e-39</td>\n",
       "      <td>2019-11-01 09:31</td>\n",
       "      <td>I2001</td>\n",
       "      <td>2019-11-01</td>\n",
       "      <td>1.572538e+09</td>\n",
       "      <td>1.572572e+09</td>\n",
       "      <td>1min</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-11-01 09:32:00</th>\n",
       "      <td>617.5</td>\n",
       "      <td>618.0</td>\n",
       "      <td>616.5</td>\n",
       "      <td>617.0</td>\n",
       "      <td>1511118</td>\n",
       "      <td>4268</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2019-11-01 09:32:00</td>\n",
       "      <td>2.117527e-39</td>\n",
       "      <td>2019-11-01 09:32</td>\n",
       "      <td>I2001</td>\n",
       "      <td>2019-11-01</td>\n",
       "      <td>1.572538e+09</td>\n",
       "      <td>1.572572e+09</td>\n",
       "      <td>1min</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                      open   high    low  close  position  trade  price  \\\n",
       "datetime                                                                  \n",
       "2019-11-01 09:30:00  618.0  618.0  617.0  617.5   1510450   2814    0.0   \n",
       "2019-11-01 09:31:00  617.5  617.5  617.0  617.5   1510914   3998    0.0   \n",
       "2019-11-01 09:32:00  617.5  618.0  616.5  617.0   1511118   4268    0.0   \n",
       "\n",
       "                                datetime        amount         tradetime  \\\n",
       "datetime                                                                   \n",
       "2019-11-01 09:30:00  2019-11-01 09:30:00  2.116591e-39  2019-11-01 09:30   \n",
       "2019-11-01 09:31:00  2019-11-01 09:31:00  2.117241e-39  2019-11-01 09:31   \n",
       "2019-11-01 09:32:00  2019-11-01 09:32:00  2.117527e-39  2019-11-01 09:32   \n",
       "\n",
       "                      code        date    date_stamp    time_stamp  type  \n",
       "datetime                                                                  \n",
       "2019-11-01 09:30:00  I2001  2019-11-01  1.572538e+09  1.572572e+09  1min  \n",
       "2019-11-01 09:31:00  I2001  2019-11-01  1.572538e+09  1.572572e+09  1min  \n",
       "2019-11-01 09:32:00  I2001  2019-11-01  1.572538e+09  1.572572e+09  1min  "
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "QA.QA_fetch_get_future_min('tdx','I2001','2019-11-01 09:30:00','2019-11-01 15:00:00').head(3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 4. 期货分笔数据\n",
    "\n",
    "QA.QA_fetch_get_future_transaction(package, code, start, end)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "QUANTAXIS>> Successfully Getting I2001 history transaction data in day 2019-11-01\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>date</th>\n",
       "      <th>hour</th>\n",
       "      <th>minute</th>\n",
       "      <th>price</th>\n",
       "      <th>volume</th>\n",
       "      <th>zengcang</th>\n",
       "      <th>natrue_name</th>\n",
       "      <th>nature_name</th>\n",
       "      <th>direction</th>\n",
       "      <th>nature</th>\n",
       "      <th>datetime</th>\n",
       "      <th>code</th>\n",
       "      <th>order</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>datetime</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-11-01 20:59:00</th>\n",
       "      <td>2019-11-01</td>\n",
       "      <td>20</td>\n",
       "      <td>59</td>\n",
       "      <td>620000</td>\n",
       "      <td>2472</td>\n",
       "      <td>1532</td>\n",
       "      <td>开仓</td>\n",
       "      <td>开仓</td>\n",
       "      <td>0</td>\n",
       "      <td>20000</td>\n",
       "      <td>2019-11-01 20:59:00</td>\n",
       "      <td>I2001</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-11-01 21:00:00</th>\n",
       "      <td>2019-11-01</td>\n",
       "      <td>21</td>\n",
       "      <td>0</td>\n",
       "      <td>619500</td>\n",
       "      <td>510</td>\n",
       "      <td>342</td>\n",
       "      <td>空开</td>\n",
       "      <td>空开</td>\n",
       "      <td>-1</td>\n",
       "      <td>10000</td>\n",
       "      <td>2019-11-01 21:00:00</td>\n",
       "      <td>I2001</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-11-01 21:00:00</th>\n",
       "      <td>2019-11-01</td>\n",
       "      <td>21</td>\n",
       "      <td>0</td>\n",
       "      <td>620000</td>\n",
       "      <td>1086</td>\n",
       "      <td>-14</td>\n",
       "      <td>空平</td>\n",
       "      <td>空平</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2019-11-01 21:00:00</td>\n",
       "      <td>I2001</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                           date  hour  minute   price  volume  zengcang  \\\n",
       "datetime                                                                  \n",
       "2019-11-01 20:59:00  2019-11-01    20      59  620000    2472      1532   \n",
       "2019-11-01 21:00:00  2019-11-01    21       0  619500     510       342   \n",
       "2019-11-01 21:00:00  2019-11-01    21       0  620000    1086       -14   \n",
       "\n",
       "                    natrue_name nature_name  direction  nature  \\\n",
       "datetime                                                         \n",
       "2019-11-01 20:59:00          开仓          开仓          0   20000   \n",
       "2019-11-01 21:00:00          空开          空开         -1   10000   \n",
       "2019-11-01 21:00:00          空平          空平          1       0   \n",
       "\n",
       "                                datetime   code  order  \n",
       "datetime                                                \n",
       "2019-11-01 20:59:00  2019-11-01 20:59:00  I2001      0  \n",
       "2019-11-01 21:00:00  2019-11-01 21:00:00  I2001      1  \n",
       "2019-11-01 21:00:00  2019-11-01 21:00:00  I2001      2  "
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "QA.QA_fetch_get_future_transaction('tdx','I2001','2019-11-01','2019-11-01').head(3)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
